<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调</title>

    <!--引入vue + axios-->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>

    <!--配置axios全局配置-->
    <script src="js/plugins/common.js"></script>
</head>
<body>
<div id="myDiv">
    <h1>欢迎~</h1>
</div>
<script type="text/javascript">
    new Vue({
        el:"#myDiv",
        data:{
            //code:'',//已弃用


        },
        methods:{

        },
        mounted(){
            //解析参数对象 http://bugtracker.itsource.cn/callback.html?code=061Z6kGa1ZdLCD0HmBFa1Fx2xm2Z6kGl&state=1
            let url = location.href;
            //let url = "http://bugtracker.itsource.cn/callback.html?code=061Z6kGa1ZdLCD0HmBFa1Fx2xm2Z6kGl&state=1";
            let paramObj = parseUrlParams2Obj(url);
            console.debug(paramObj);
            //获取发送请求参数
            //this.code=paramObj.code;
            //发起微信登录请求  调用微信登录接口 ，参数paramObj.code
            this.$http.get("/login/wechat/"+paramObj.code).then(res=>{
                if(res.data.success){
                    alert("登录成功！")
                    //1.保存返回的token，logininfo到localStorage
                    let {token,loginInfo} = res.data.resultObj;//等同于 let token=res.resultObj.token ；...
                    localStorage.setItem("token",token);
                    localStorage.setItem("loginInfo",JSON.stringify(loginInfo));
                    //2.跳转到首页，显示当前登录人
                    location.href="/index.html";
                }else{//如果没有,获取参数，跳转到绑定页面
                    var access_token=res.data.resultObj.access_token;
                    var openid=res.data.resultObj.openid;
                    location.href="/binder.html?accessToken="+access_token+"&openid="+openid;
                }
            }).catch(res=>{
                alert("系统繁忙，稍后重试~")
            })
            /*this.$http.post("/login/wechat",params)//作为参考
                .then(result=>{
                    result = result.data;
                    if(result.success){ //已经关联了 免密登录之后，需要调到主页
                        //做登录
                        //提示
                        alert("登录成功！")
                        //1.保存返回的token，logininfo到localStorage
                        let {token,logininfo} = result.resultObj;
                        localStorage.setItem("token",token);
                        localStorage.setItem("loginInfo",JSON.stringify(logininfo));
                        //2.跳转到首页，显示当前登录人
                        location.href="index.html";
                    }else{ //没有关联跳转绑定页面   "?accessToken="+accessToken+"&openId="+openId;
                        let binderUrl = "http://bugtracker.itsource.cn/binder.html"+result.resultObj;
                        location.href = binderUrl;
                    }
                })
                .catch(result=>{
                    alert("系统错误");
                    console.log(result);
                })*/
        }
    });
</script>
</body>
</html>